<template>
  <div>
    <el-table :data="userlist" border style="width: 100%">
      <el-table-column prop="uid" label="用户编号" width="180"> </el-table-column>
      <el-table-column prop="username" label="用户名称" width="180"> </el-table-column>
      <el-table-column prop="rolename" label="所属角色" width="180"> </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="item">
          <div>
            <el-tag v-if="item.row.status == 1" type="success">启用</el-tag>
            <el-tag v-else type="danger">禁用</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="item">
          <div>
            <el-button 
            @click="edit(item.row.uid)" 
            type="primary" 
            size="mini" 
            circle 
            icon="el-icon-edit"
            ></el-button>
            <el-button 
            @click="del(item.row.uid)" 
            type="danger" 
            size="mini" 
            circle 
            icon="el-icon-delete"
            ></el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination @current-change="changepage" :page-size="pageSize" background layout="prev, pager, next" :total="count">
    </el-pagination>
  </div>
</template>

<script>
import { userdelete } from '@/request/api';
import { mapActions, mapGetters } from 'vuex';
export default {
  computed: {
    ...mapGetters({
      userlist: 'admin/getUser',
      pageSize:'admin/getSize',
      count:'admin/getCount'
    })
  },
  mounted() {
    this.getUserAction();
    this.getCount()
  },
  methods: {
    ...mapActions({
      getUserAction: 'admin/getUserAction',
      getCount:'admin/getCountAction',
      changePageAction:'admin/changePageAction'
    }),
    //求换页面事件
    changepage(n){
      console.log(n);
      this.changePageAction(n)
    },
    edit(id) {
      this.$emit('edit', id)
    },
    del(uid) {
      this.$confirm('你确定要删除这条数据吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        userdelete({ uid }).then((res) => {
          console.log(res,'dddddddd');
          console.log(uid,'1111');
          if (res.code == 200) {
            this.$message.success(res.msg);
            //重新调用列表
            this.getUserAction()
            //重新调用总数
            this.getCount()
          } else {
            this.$message.error(res.msg)
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    }
  }
};
</script>

<style scoped>

</style>
